/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package STUDENT.NGUYENSANG.OOPs.QuanLiThuVien;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
 *
 * @author NSPDL
 */
public class NhapBangQanLi {
    public static List<BangQuanLi> ListBQL=new ArrayList<>();
    public BangQuanLi newBQL()
    {
        Scanner input1=new Scanner(System.in);
        BangQuanLi bql=null;
        try{
            System.out.println("Nhap ma ban doc: "); int mabd=input1.nextInt();
            System.out.println("Nhap ma sach: "); int mas=input1.nextInt();
            System.out.println("Nhap so cuong ban muon: ");
            int soCuon=input1.nextInt();
            if(soCuon>3){
                System.out.println("nhap loi");
            }else
            {
                if(soCuon <0)
                {
                    System.out.println("Bat buoc lon hon 0: ");
                    
                }
                else
                {
                    //int maQL=ListBQL.size()+1000;
                    bql=new BangQuanLi(NhapSach.ListSach.get(mas),NhapBanDoc.ListbanDoc.get(mabd),soCuon);
                }
            }

        }catch(Exception e)
        {
            System.out.println("Erro!!"+e.getMessage());
        }
        return bql;
    }
    public void AddBQl()
    {
        System.out.println("Nhap bang Quan Li:");
        BangQuanLi BQL=newBQL();
        if(BQL!=null)
        {
            ListBQL.add(BQL);
        }
    }
    public void loadBD(){
        for(BangQuanLi i : ListBQL){
            for(BanDoc j : NhapBanDoc.ListbanDoc){
                if(i.getMaBanDoc() == j.getMaID()){
                    i.setBandoc(j);
                }
            }
        }
    }
    public boolean Kiemtra(int maBD, int maS)
    {
        int dem = 0;
        for(BangQuanLi i : ListBQL){
           if(i.getMaSach() == maS &&  i.getMaBanDoc() == maBD){
               dem ++;
           }
        }
        if(dem > 5){
            return true;
        }
        return false;
    }
    public void ThemSach()
    {
        Scanner input2=new Scanner(System.in);
        int maS, maBd;
        System.out.println("Nhap ma ban doc");
        maBd=input2.nextInt();
        System.out.println("Nhap Ma Sach: ");
        maS=input2.nextInt();
        if(Kiemtra(maBd, maS))
        {
            System.out.println("Ban khong dc muon nua");
            return;
        }
        else
        {            
            AddBQl();
        }   
    }
    public void showBQL()
    {
        System.out.println("Thong tin bang quna li: ");
        for(BangQuanLi index: ListBQL)
        {
            System.out.println(""+index);
        }
    }
}
